package com.study.string;

import java.util.Scanner;

/*
* 练习题：模拟用户登录
* */
public class StringExec8 {
    public static void main(String[] args) {
        //1.定义正确的登录名和密码
        String okLoginName = "admin";
        String okPassword = "123456";

        //2.定义一个循环，循环3次，让用户登录
        Scanner sc = new Scanner(System.in);
        int count = 1;
        while(true){

            System.out.println("--------------------------------");
            System.out.println("请你输入登录名称：");
            String loginName = sc.next();
            System.out.println("请你输入登录密码：");
            String password = sc.next();

            // 3.判断登录是否成功
            if (count >= 3){
                System.out.println("你今天的登录机会已经用完,请明天再试！");
            }else {
                if (okLoginName.equals(loginName)){
                    if (okPassword.equals(password)){
                        System.out.println("登录成功！欢迎进入系统随意浏览~~~~~");
                        break;
                    }else {
                        // 密码错误了
                        System.out.println("你的密码不正确！你还剩余"+(3-count)+"次登录机会！");
                        count++;
                    }
                }else {
                    System.out.println("你的登录名不正确！你还剩余"+(3-count)+"次登录机会！");
                    count ++;
                }
            }


        }
    }
}
